package 笔试.美团;


/**
 * @author:谢君臣
 * @Date:2021/8/15-8:22
 * @version:1.0
 * @function:
 */
import java.util.Scanner;
public class MT81504 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt(),n = scanner.nextInt();
        int x = scanner.nextInt(),y = scanner.nextInt();
        int[] stup = new int[n+1];
        int[] car = new int[n+1];
        int[] wait = new int[n+1];
        int i = 1,max = 0;
        while (i<=n){
            int x1 = scanner.nextInt(),y1 = scanner.nextInt();
            car[i] = scanner.nextInt();
            stup[i] = scanner.nextInt();
            i++;
        }
        for (int t : car) max = t + max;  // 计算全部打车需要时间
        int stup_time = 0; // 步行到当前节点时间
        int j = 0,T = Integer.MAX_VALUE;
        while (j<n)
        {
            stup_time = stup_time+stup[j];
            wait[j] = scanner.nextInt();
            if (wait[j]>=stup_time) wait[j] = wait[j]-stup_time;
            int temp = wait[j]+max;
            max = max-car[j]+stup[j];
            T = Math.min(T,temp);
            j++;
        }
        System.out.println(T);
    }
}
